<template>
  <div class="item-box" ref="itemBox">
    <div class="item-top">
      <titles :title="props.info.text" />
      <div class="textMax">
        <textMax :data="props.info.remarks" :maxLen="141" :tip="'展开'" :id="props.info.id" />
        <!-- <HwScrollYVue :remarks="props.info.remarks" :maxLen="141"></HwScrollYVue> -->
      </div>
    </div>

    <div style="position: relative">
      <div class="scroll-box" id="scroll-box2" ref="scrollBox">
        <div
          @mouseenter="imgEnter(index, props.info.children)"
          @mouseleave="imgLeave(index, props.info.children)"
          class="exhibits-item content-item"
          @click="pathChild(props.info.children, index)"
          style="cursor: pointer;"
          v-for="(item, index) in props.info.children"
          :key="index"
        >
          <div class="item-img">
            <img
              v-if="item.value"
              :src="
                item.value
                  ? urls + item.value + '?imageView2/1/w/240/h/240/format/webp'
                  : 'http://101.34.143.36:8890/api/image/387939155165253/h_296,w_500'
              "
              alt=""
            />
            <UnitImageNull v-else></UnitImageNull>
            <div class="shadow"></div>
          </div>

          <span
            class="titleText"
            :class="'titleText' + props.info.children[index].id"
            :style="{
              fontSize: store.styleInfo.mintitleSize,
              fontFamily: store.styleInfo.textFamily,
              color: store.styleInfo.fontColor,
              fontweight: 'bold',
            }"
            >{{ item.text }}</span
          >
          <div class="line" :class="'line' + props.info.children[index].id"></div>
          <div class="leftTitle">
            <span
              :style="{
                fontSize: store.styleInfo.contentSize,
                fontFamily: store.styleInfo.textFamily,
                color: '#666',
              }"
              >{{ item.remarks }}</span
            >
          </div>
        </div>
      </div>
      <div
        class="page"
        :class="'solid-border' + store.styleInfo.coflorType"
        :style="{
          color: store.styleInfo.themeColor,
        }"
      >
        {{ current + 1 < 10 ? '0' + (current + 1) : current + 1 }}/{{
          props.info.children.length < 10 ? '0' + props.info.children.length : props.info.children.length
        }}
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { ref } from 'vue';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import textMax from './component/textMax.vue';
import { handlemouse } from '@/utils/minxin';
import { onMounted } from 'vue';
import { useProjectStore } from '@/store';
import { useRouter, useRoute } from 'vue-router';
import { imgEnter, imgLeave } from './component/hover';
import HwScrollYVue from './component/hwScrollY.vue';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
const itemBox = ref(null);
const scrollBox = ref(null);
const router = useRouter();
const route = useRoute();
const title = '';
const store = useProjectStore();
const props = defineProps({
  info: {
    type: Object,
  },
});
const current = ref(0);
const pathChild = (e: any, index) => {
  store.setchildModel(e);
  router.push({
    path: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { projectId: localStorage.getItem('projectId'), current: index },
  });
};
onMounted(() => {
  // handlemouse('scroll-box2');

  scrollBox.value.addEventListener('scroll', (e) => {
    const scrollDistance = e.target.scrollTop;
    console.log('进入', scrollDistance);
    current.value = Math.floor(scrollDistance / 350);
    console.log('current---', current.value);
  });

  animation();
});
const animation = () => {
  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        itemBox.value.classList.add('animation-box');
        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        if (itemBox.value) {
          itemBox.value.classList.remove('animation-box');
        }
      }
    });
  });
  observer.observe(itemBox.value);
};
</script>

<style lang="less" scoped>
@import './index.less';
// @import './component/hover.less';
.item-box {
  width: 100%;
  // height: calc(100vh - 80px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  opacity: 0;
}
.exhibits-text {
  width: 75%;
}
.exhibits-item {
  width: 500px;
  // display: flex;
  // flex-direction: column;
  margin-bottom: 50px;

  .item-img {
    position: relative;
    width: 500px;
    height: 296px;
    overflow: hidden;
    margin-bottom: 24px;
    img {
      width: 500px;
      height: 296px;
    }
  }
}

.item-btm {
  display: flex;
  flex-direction: column;
  //   width: 100%;
  padding: 24px 32px;
}
.exhibits-List {
  width: 100%;
}
.scroll-box {
  // display: flex;
  // width: 520px;
  height: calc(100vh - 72px - 80px);
  flex: 1;
  //   height: 346px;
  //   white-space: nowrap;
  overflow-y: scroll;
  padding-bottom: 270px;
  padding-left: 40px;
}
.titleText {
  margin-top: 24px;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 20px;
  font-family: SourceHanSerifCN-Bold, SourceHanSerifCN !important;
}
.item-top {
  // width: 580px;
  min-height: 300px;
  overflow: hidden;
  .titleText {
    text-align: left;
    padding: 0;
  }
}
.textMax {
  width: 580px !important;
  margin-top: 144px;
}
.hw-flex-style-c-c {
  justify-content: left;
}
.page {
  position: absolute;
  top: 0px;
  left: -20px;
}
.leftTitle {
  // width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  line-height: 32px;

  font-family: SourceHanSerifCN-Medium, SourceHanSerifCN !important;
}
::-webkit-scrollbar {
  width: 0;
}
.solid-border1 {
  color: #cfbda8;
}
.solid-border2 {
  color: #8f9ebf;
}
.solid-border3 {
  color: #b9463f;
}
.solid-border4 {
  color: #343029;
}
.solid-border5 {
  color: #171719;
}
.content-item img {
  transition: all 0.5s;
}
.content-item {
  position: relative;
  overflow: hidden;
}
.shadow {
  width: 100%;
  height: 296px;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}
.content-item:hover .shadow {
  background: rgba(0, 0, 0, 0.4);
}
.content-item:hover img {
  transform: scale(1.1);
}
.line {
  width: 0px;
  height: 2px;
  background: #000;
  transform: all 0.5s;
  margin-bottom: 8px;
}
</style>
